var express = require('express');
var router = express.Router();
var fs = require('fs')
var db = require('../mysql/db');


router.get('/list', async (req, res) => {
    try {
        var list = await db.query(" select * from student ");
    } catch (err) {
        console.log('error=', err);
    }
    res.send({
        list: list[0]
    })
})

router.post('/login', async (req, res) => {
    let { name, password } = req.query
    let code, msg,data
    try {
        let [list,res] = await db.query(" select * from u where name=? and password=? ", [name, password]);   
        if (list.length) {      
            code = 200
            msg = '登录成功'
            data = list[0]
        } else {
            code = 201
            msg = '登录失败'
        }
    } catch (err) {
        console.log('error=', err);
    }    
    res.send({
        code,
        msg,
        list:data
    })
})



module.exports = router;
